#ifndef HTTPREQUEST_H
#define HTTPREQUEST_H
#include <Buffer.h>
#include <stdbool.h>
#include <string.h>
#include <Httpresponse.h>
#include <assert.h>
#include <ctype.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <stdio.h>
#include <dirent.h>

struct RequestHeader {
    char *key;
    char *value;
};

enum HttpRequestState {
    ParseReqLine,
    ParseReqHeaders,
    ParseReqBody,
    ParseReqDone,
};

struct HttpRequest {
    char* method;
    char* url;
    char* version;
    struct RequestHeader* reqHeaders;
    int reqHeadersNum;
    enum HttpRequestState curState;
};

struct HttpRequest* httpRequestInit();

void httpRequestReset(struct HttpRequest* req);

void httpRequestResetEx(struct HttpRequest* req);

void httpRequestDestroy(struct HttpRequest* req);


bool parseHttpRequest(struct HttpRequest* request, struct Buffer* readBuf,
                      struct HttpResponse* response, struct Buffer* sendBuf, int socket);

bool parseHttpRequestLine(struct HttpRequest* request, struct Buffer* readBuf);

bool parseHttpRequestHeader(struct HttpRequest* request, struct Buffer* readBuf);

void httpRequestAddHeader(struct HttpRequest* request, const char * key, const char* value);

bool processHttpRequest(struct HttpRequest* request, struct HttpResponse* response);

void decodeMsg(char* to, char* from);

const char* getFileType(const char* name);

void sendFile(const char* fileName, struct Buffer* sendBuf, int cfd);
void sendDir(const char* dirName, struct Buffer* sendBuf, int cfd);







#endif // HTTPREQUEST_H
